package expression;

import java.util.LinkedList;

public class FnArithSubtract extends Fn implements FnNumber, FnString {

	@Override
	protected boolean isAcceptableChild(Fn fn) {
		return (fn instanceof FnNumber);
	}
	
	@Override
	protected boolean isAcceptableParam(Object o) {
		return (o instanceof Number);
	}

	@Override
	public int getNParam() {
		return 2;
	}

	@Override
	protected int precedence() {
		return 5;
	}

	@Override
	protected Object value(LinkedList<Object> param) {
		Double out = new Double(0);
		int f = 1;
		for (Object operand : param) {
			if (operand instanceof Integer)
				out += (Integer) operand * f;
			else if (operand instanceof Float)
				out += (Float) operand * f;
			else if (operand instanceof Double)
				out += (Double) operand * f;
			f = -1;
		}
		return out;
	}

	@Override
	public String symbol() {
		return "-";
	}

	@Override
	protected String[] notation() {
		return new String[]
		{ "", " - ", "" };
	}

}
